# Maintainer: wszqkzqk <wszqkzqk@qq.com>

_realname=python-pikepdf
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=9.7.0
pkgrel=1
pkgdesc='Read and write PDFs with Python, powered by qpdf'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/pikepdf/pikepdf'
msys2_references=(
  "archlinux: $_realname"
)
license=('spdx:MPL-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-deprecated"
         "${MINGW_PACKAGE_PREFIX}-python-lxml"
         "${MINGW_PACKAGE_PREFIX}-python-packaging"
         "${MINGW_PACKAGE_PREFIX}-python-pillow"
         "${MINGW_PACKAGE_PREFIX}-qpdf")
makedepends=(git
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-pybind11"
             "${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-hypothesis"
              "${MINGW_PACKAGE_PREFIX}-python-psutil"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-xdist")
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('98855aa36d8165368c445e96412930d1886e7ea2b1666b26a91b1995e88a6a7e')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r pikepdf-${pkgver} "python-build-${MSYSTEM}"
}

build() {
  cd "python-build-${MSYSTEM}"
  python -m build --wheel --no-isolation --skip-dependency-check
}

check() {
  cd "python-build-${MSYSTEM}"
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  test-env/bin/python -m pytest -v
}

package() {
  cd "python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
      --destdir="$pkgdir" dist/*.whl
  install -Dm644 LICENSE.txt -t "${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname"
}
